﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Golf_ProAttrDetailZSG.aspx.cs"
    Inherits="Golf.WebUI.AdminShow.AttributeManagement.Golf_ProAttrDetailZSG" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>产品属性中间连接数据</title>
    <link href="../Style/tablelist.css" rel="stylesheet" type="text/css" />

    <script src="../../Script/ymPrompt/ymPrompt.js" type="text/javascript"></script>

    <link href="../../Script/ymPrompt/skin/bluebar/ymPrompt.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        /**********判断是否加载jquey***************/
        window.jQuery || document.write('<script src="../../Script/jquery/jquery-1.4.1-vsdoc.js" type="text/javascript"><\/script>');
    </script>

    <script type="text/javascript">
        $(function() {
            $("tbody tr:even").addClass("s_oushuhang"); //偶数行的背景色
            $("tbody tr:odd").addClass("s_jishuhang"); //奇数行的背景色
            //光棒效果
            $('tbody>tr').hover(function() {
                $(this).addClass("s_mouseover");
            }, function() {
                $(this).removeClass("s_mouseover");
            });
        });
    </script>

    <link href="../../Script/My97DatePicker/skin/whyGreen/datepicker.css" rel="stylesheet"
        type="text/css" />

    <script src="../../Script/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

    <script src="../Script/Window.js" type="text/javascript"></script>

    <script src="../../Script/jquery/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {
            var P_attrID = "<%=attrIDS %>"; //获取父类的属性的id
            var is_modify = "<%=isModify %>"; //是否修改
            var P_datelID = "<%=pro_datelId %>"; //详细属性的id
            if (is_modify == "yes") {
                $(".is__modify").html("<%=pro_datelHtml %>");
            }
            if (P_attrID != null && P_attrID != "") {
                var ps = P_attrID.split(',');
                for (var i = 0; i < ps.length; i++) {
                    $(".chk_Preat[value='" + ps[i] + "']").attr("checked", true);
                }
            }
            jQuery("#_One :gt(0)").remove();
            jQuery.getJSON("../../HttpHandler/Attribute/Golf_ProAttrDetailZSG.ashx", { action: "rad_Type" }, function(Province) {
                jQuery.each(Province, function(i, item) {
                    jQuery("<option class='_content'></option>")
                    .val(item["Id"])
                    .text(item["TypeName"])
                    .appendTo(jQuery("#_One"));
                });
            });
            //属性父类筛选器
            $("._rad_action").click(function() {
                jQuery("#_One :gt(0)").remove();
                jQuery.getJSON("../../HttpHandler/Attribute/Golf_ProAttrDetailZSG.ashx", { action: $(this).val() }, function(Province) {
                    jQuery.each(Province, function(i, item) {
                        jQuery("<option class='_content'></option>")
                    .val(item["Id"])
                    .text(item["TypeName"])
                    .appendTo(jQuery("#_One"));
                    });
                });

            });
            //选择商品
            $("#_One").click(function() {
                jQuery("#_Two :gt(0)").remove();
                var Action;
                var _a = $("._rad_action:checked").val();
                if (_a == "rad_Type") {
                    Action = "type_pro";
                }
                if (_a == "rad_pingpai") {
                    Action = "type_pingpai";
                }
                jQuery.getJSON("../../HttpHandler/Attribute/Golf_ProAttrDetailZSG.ashx", { action: Action, ids: $(this).val() }, function(Province) {
                    jQuery.each(Province, function(i, item) {
                        jQuery("<option class='_content'></option>")
                    .val(item["Id"])
                    .text(item["Pro_Name"])
                    .appendTo(jQuery("#_Two"));
                    });
                });
            });
            ///属性选择器
            $(".chk_Preat").click(function() {
                var P_ID = $(this).val();
                var p_d_id = P_datelID.split(',');
                if ($(this).attr("checked")) {
                    var str_ = "";
                    str_ += "<div id='div_" + P_ID + "' style='clear: both;border: 1px solid #ccc;width: 90%;line-height: 20px; height:20px; margin-top:3px'>";
                    jQuery.getJSON("../../HttpHandler/Attribute/Golf_ProAttrDetailZSG.ashx", { action: "attr", id: $(this).val() }, function(Province) {
                        $("#div_" + P_ID).remove();
                        jQuery.each(Province, function(i, item) {
                            str_ += "<div class='div_chk'><input type='checkbox' class='chk_child'value='" + item["ID"] + "' />" + item["AttrChild"] + "</div>";
                        });
                        str_ += "</div>";
                        $("#childAttr").append(str_);
                        for (var i = 0; i < p_d_id.length; i++) {
                            $(".chk_child[value='" + p_d_id[i] + "']").attr("checked", true);
                        }
                    });
                } else {
                    $("#div_" + P_ID).remove();
                }
            });

            //保存 数据  属性字段最重要了

            $("#btnSave").click(function() {
                //产品id
                var pro_id = "<%=pro_id %>";
                if (pro_id == "0") {
                    pro_id = $("#_Two").select().val();
                    if (pro_id == null || pro_id == "-1" || pro_id == "") {
                        ymPrompt.alert("请选择产品！");
                        return false;
                    }
                }
                //父类属性编号
                var P_attr_id = $(".chk_Preat:checked");
                var strIds = "";
                if (P_attr_id.length == 0) {
                    ymPrompt.alert("您没有选择父类属性编号！");
                    return false;
                }
                if (P_attr_id.length != 0) {
                    P_attr_id.each(function(i, item) {
                        strIds += item.value + ",";
                    });
                    strIds = strIds.substring(0, strIds.length - 1);
                }
                //父类属性编号
                var d_attr_id = $(".chk_child:checked");
                var d_ids = "";
                if (d_attr_id.length == 0) {
                    ymPrompt.alert("您没有选择子类属性编号！");
                    return false;
                }
                if (d_attr_id.length != 0) {
                    d_attr_id.each(function(i, item) {
                        d_ids += item.value + ",";
                    });
                    d_ids = d_ids.substring(0, d_ids.length - 1);
                }
                //执行保存功能
                //alert("pro_id:" + pro_id + "     P_attr_id:" + strIds + "   d_attr_id:" + d_ids);
                // return false;
                $.ajax({
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded",
                    url: "Golf_ProAttrDetailZSG.aspx?" + Math.random(),
                    data: {
                        "action": "save",
                        "pro_id": pro_id,
                        "P_attr_id": strIds,
                        "d_attr_id": d_ids,
                        "_action": $("#_action").val(),
                        "_Id": "<%=_Id %>"
                    },
                    success: function(msg) {
                        alert(msg.split(',')[0]);
                        window.parent.location.href = window.parent.location.href;
                        ymPrompt.close();
                        //刷新框架
                    },
                    error: function(xhr) {
                        alert(xhr.responseText);
                    }
                });
            });

        });
    </script>

    <style type="text/css">
        .div_chk
        {
            float: left;
            width: 220px;
        }
        ._content
        {
            text-align: center;
        }
        .style1
        {
            width: 19%;
        }
        .style2
        {
            width: 678px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="table">
            <tr>
                <!--判断当前的操作-->
                <input type="hidden" runat="server" id="_action" />
                <td height="25" align="right" class="style1">
                    Id 主键 ：
                </td>
                <td height="25" align="left" class="style2">
                    <asp:Label ID="lblId" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td height="25" align="right" class="style1">
                    产品ID ：
                </td>
                <td height="25" align="left" class="style2 is__modify">
                    <div style="float: left; width: 273px; height: 182px;">
                        筛选条件：
                        <input id="rad_Type" type="radio" class="_rad_action" value="rad_Type" name="rad"
                            checked="checked" />
                        <label for="rad_Type">
                            按类型</label>
                        <input id="rad_pingpai" type="radio" class="_rad_action" value="rad_pingpai" name="rad" />
                        <label for="rad_pingpai">
                            按品牌</label>
                        <select id="_One" size="18" style="height: 150px;">
                            <option value="-1" class="_content">--请选择[品牌/类型]--</option>
                        </select>
                    </div>
                    <div style="width: 371px; float: right; height: 182px;">
                        产品列表↓
                        <select id="_Two" size="18" style="height: 150px;" runat="server">
                            <option value="-1" class="_content">--请选择产品--</option>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td height="25" align="right" class="style1">
                    产品属性父类ID ：
                </td>
                <td height="25" align="left" class="style2">
                    <%--产品父类自动代码--%>
                    <asp:Repeater ID="Repeater1" runat="server">
                        <ItemTemplate>
                            <div class="div_chk">
                                <input type="checkbox" class="chk_Preat" value="<%#Eval("id") %>" /><%#Eval("AttrParent")%>
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>
                </td>
            </tr>
            <tr>
                <td height="25" align="right" class="style1">
                    产品详细 属性 ：
                </td>
                <td height="25" align="left" class="style2">
                    <%--属性详细自动代码--%>
                    <asp:Repeater ID="Repeater2" runat="server">
                        <ItemTemplate>
                            <div class="div_chk" style="border: 1px solid red; margin: 2px; color: Red;">
                                <input type="checkbox" class="_chk_child" value="<%#Eval("id") %>" /><%#Eval("AttrChild")%>
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>
                    <div id="childAttr" runat="server">
                    </div>
                </td>
            </tr>
            <tr>
                <td class="tdbg" align="center" valign="bottom" colspan="2">
                    <input id="btnSave" type="button" value="保存" class="btn" />
                    <asp:Button ID="btnCancle" runat="server" Text="取消" CssClass="btn" OnClick="btnCancle_Click">
                    </asp:Button>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
